package com.jumi.microservice.controller.invoice;

import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.dto.invoice.*;
import com.jumi.microservice.service.invoice.InvoiceApiService;
import com.jumi.microservice.service.invoice.admin.InvoiceService;
import com.jumi.microservice.utils.NuoNuoUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(tags = {"C端--发票相关接口"})
@RestController
@RequestMapping("api/invoice")
public class InvoiceApiController extends BaseController {
    @Resource
    private InvoiceApiService invoiceApiService;
    @Resource
    private InvoiceService invoiceService;
    @Resource
    private NuoNuoUtil nuoNuoUtil;

    @GetMapping("/invoiceView")
    @ApiOperation("发票详情---图片页")
    public ResponseResult<InvoiceApiResponse> invoiceView(InvoiceApiRequest invoiceApiRequest) {
        ResponseResult<InvoiceApiResponse> result = new ResponseResult<>();
        InvoiceApiResponse invoiceApiView = invoiceApiService.invoiceApiView(invoiceApiRequest);
        result.setData(invoiceApiView);
        return result;
    }

    /*@GetMapping("/invoiceListStatus")
    @ApiOperation("发票状态列表")*/
    TableDataInfo<InvoiceApiStatusResponse> invoiceListStatus(InvoiceApiRequest invoiceApiRequest) {
        return invoiceApiService.invoiceListStatus(invoiceApiRequest);
    }

    @GetMapping("/invoiceListDetails")
    @ApiOperation("订单发票详情")
    public ResponseResult<InvoiceApiStatusResponse> invoiceListDetails(InvoiceApiDetailRequest invoiceApiDetailRequest) {
        ResponseResult<InvoiceApiStatusResponse> result = new ResponseResult<>();
        InvoiceApiStatusResponse invoiceApiStatusResponse = invoiceApiService.invoiceListDetails(invoiceApiDetailRequest);
        result.setData(invoiceApiStatusResponse);
        return result;
    }

    @PutMapping(value = "/invoiceRed")
    @ApiOperation("前端发票作废")
    public ResponseResult<Boolean> invoiceRed(InvoiceRedRequest invoiceRedRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        result.setData(invoiceService.invoiceRed(invoiceRedRequest));
        return result;
    }

    @GetMapping("/invoiceListOrder")
    @ApiOperation("根据订单编号查询发票列表----列表页")
    TableDataInfo<InvoiceOrderSnListResponse> invoiceListOrder(InvoiceOrderSnListRequest invoiceOrderSnListRequest) {
        return invoiceApiService.invoiceListOrder(invoiceOrderSnListRequest);
    }

    @PostMapping("/addInvoice")
    @ApiOperation("前段订单发票添加---[订单列表申请发票*修改订单发票信息时使用]")
    public ResponseResult<Integer> addInvoice(InvoiceAddRequest invoiceAddRequest) {
        ResponseResult<Integer> result = new ResponseResult<>();
        //获取当前用户ID
        invoiceAddRequest.setUid(getApiUserId().longValue());
        //invoiceAddRequest.setUid(9999L);
        result.setData(invoiceService.addInvoice(invoiceAddRequest));
        return result;
    }

    @PostMapping("/addInvoiceUserList")
    @ApiOperation("前段用户发票抬头列表添加")
    public ResponseResult<Map<String, String>> addInvoiceUserList(InvoiceAddUserRequest invoiceAddUserRequest) {
        //获取当前用户ID
        invoiceAddUserRequest.setUid(getApiUserId().longValue());
        //invoiceAddUserRequest.setUid(9999L);
        return success(invoiceService.addInvoiceUserList(invoiceAddUserRequest));
    }

    @GetMapping("/invoiceListUser")
    @ApiOperation("前段根据uid 发票抬头类型查询发票抬头列表")
    TableDataInfo<InvoiceUserListResponse> invoiceListUser(InvoiceUserListRequest invoiceUserListRequest) {
        //获取当前用户ID
        invoiceUserListRequest.setUid(getApiUserId().longValue());
        return invoiceService.invoiceListUser(invoiceUserListRequest);
    }

    @PostMapping(value = "/invoiceEditListUser")
    @ApiOperation("前端用户发票抬头列表修改")
    public ResponseResult<Boolean> invoiceEditListUser(InvoiceUserListEditRequest invoiceUserListEditRequest) {
        //获取当前用户ID
        invoiceUserListEditRequest.setUid(getApiUserId().longValue());
        return invoiceService.invoiceEditListUser(invoiceUserListEditRequest);
    }

    /*@PostMapping(value = "/addOrderInvoice")
    @ApiOperation("订单提交发票ruiguang专用")*/
    public Integer addOrderInvoice(InvoiceAddRequest invoiceAddRequest) {
        //获取当前用户ID
        invoiceAddRequest.setUid(getApiUserId().longValue());
        return invoiceService.addOrderInvoice(invoiceAddRequest);
    }

    @ApiOperation("第三方开票")
    @PostMapping("/invoice")
    public ResponseResult<String> invoice(InvoiceOneRequest request) {
        return invoiceApiService.invoice(request);
    }

    @ApiOperation("根据流水号查询")
    @PostMapping("/getInvoicePdf")
    public ResponseResult<String> getInvoicePdf(String serialNumber) {
        ResponseResult<String> responseResult = new ResponseResult<>();
        responseResult.setData(invoiceService.getInvoicePdf(serialNumber));
        return responseResult;
    }
}
